import request from '@/utils/request'

export default {
    search(searchMap) {
        if (searchMap.gid != "") {
            const req = request({
                method: 'get',
                url: '/dgut/getGoodsMessageById',
                params: {
                    gid: searchMap.gid
                }
            })
            return req;
        } else if (searchMap.gname != "") {
            const req = request({
                method: 'get',
                url: '/dgut/getGoodsMessageByName',
                params: {
                    gname: searchMap.gname
                }
            })
            return req;
        } else if (searchMap.gprice != "") {
            const req = request({
                method: 'get',
                url: '/dgut/getGoodsMessageByPrice',
                params: {
                    gprice: searchMap.gprice
                }
            })
            return req;
        } else if (searchMap.gtype != "") {
            const req = request({
                method: 'get',
                url: '/dgut/getGoodsMessageByType',
                params: {
                    gtype: searchMap.gtype
                }
            })
            return req;
        } else {
            const req = request({
                method: 'get',
                url: '/dgut/getAllGoodsMessage'
            })
            return req;
        }
    },
    getAllGoodsMessage(){
        const req = request({
            method: 'get',
            url: '/dgut/getAllGoodsMessage'
        })
        return req;
    },
    deleteOneGoods(gid){
        const req = request({
            method: 'delete',
            url: '/dgut/deleteOneGoodsMessage',
            params:{
                gid
            }
        })
        return req;
    },
    getOneGoods(gid){
        const req = request({
            method: 'get',
            url: '/dgut/getGoodsMessageById',
            params: {
                gid
            }
        })
        return req;
    },
    editOneGoods(Message){
        const req = request({
            method: 'put',
            url: '/dgut/updateOneGoodsMessage',
            params: {
                gid: Message.gid,
                gname: Message.gname,
                gtype: Message.gtype,
                gprice: Message.gprice,
                gcounts: Message.gcounts

            }
        })
        return req;
    },
    addOneGoods(goodsMessage) {
        console.log(goodsMessage);
        const req = request({
            method: 'post',
            url: '/dgut/addOneGoodsMessage',
            params: {
                gname: goodsMessage.gname,
                gtype: goodsMessage.gtype,
                gprice: goodsMessage.gprice,
                gcounts: goodsMessage.gcounts

            }
        })
        return req;
    }
}